package com.sum.common.utils;

import java.util.Iterator;
import java.util.Map;

public class MapUtils {
    public static String mapToString(Map<String, Object> map) {
        if (map == null || map.isEmpty()) {
            return "{}";
        }

        StringBuilder sb = new StringBuilder();
        sb.append("{");

        for (Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator(); it.hasNext();) {
            Map.Entry<String, Object> entry = it.next();
            sb.append("\"").append(entry.getKey()).append("\":");

            // 处理值
            Object value = entry.getValue();
            if (value == null) {
                sb.append("null");
            } else {
                sb.append("\"").append(value.toString()).append("\"");
            }

            if (it.hasNext()) {
                sb.append(",");
            }
        }

        sb.append("}");
        return sb.toString();
    }
}